<?php

namespace App\Admin\Actions\Admin;

use App\Models\Order;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;

class OrderAudit extends RowAction
{
    protected $selector = '.order-audit';

    public $name = '审核';

    public function handle(Order $order,Request $request)
    {

        if($request->result == 1){
            //通过
            $order->state = Order::ORDER_STATE_AUDIT_WAITING;
        }elseif ($request->result == 2){
            //拒绝
            $order->state = Order::ORDER_STATE_AUDIT_REFUSE;
        }
        $order->save();
        return $this->response()->success('操作成功')->refresh();
    }

    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-default order-audit"></a>
HTML;
    }

    public function form()
    {
        $type = [
            1 => '通过',
            2 => '拒绝',
        ];

        $this->radio('result', '审核结果')->options($type);
    }
}
